//
//  UIImage+Render.m
//  BuDeJie
//
//  Created by haoran on 16/3/31.
//  Copyright © 2016年 xuhaoran. All rights reserved.
//

#import "UIImage+Render.h"

//返回一个未经渲染的图片
@implementation UIImage (Render)

+(UIImage *)imageNameWithOringinal:(NSString *)imageName{
    UIImage * image = [UIImage imageNamed:imageName];
    
    return [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}

//生成一个圆角矩形
-(UIImage *)circleImage{
    
    //裁剪图片 开启上下文
    //1.开启上下文
    // scale:比例因素 点:像素比例 0:自动识别比例因素 retina屏幕为2 ,6Plus为3
    UIGraphicsBeginImageContextWithOptions(self.size, NO, 0);
    //2.描述圆形裁剪路径
    UIBezierPath * clipPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, self.size.width, self.size.height)];
    //3.设置为裁剪区域
    [clipPath addClip];
    //4.画图片
    [self drawAtPoint:CGPointZero];
    //5.取出图片
    UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
    //6.关闭上下文
    UIGraphicsEndPDFContext();
    
    return image;
}

// 生成一个圆角矩形的图片
+(UIImage *)xhr_circleImageNamed:(NSString *)name{

    return [[UIImage imageNamed:name] circleImage];

}

@end
